﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;

public partial class Test_ExportSiteMap : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ExportSiteMap_PhongTro();
		//ExportSiteMap_TinTuc();
        //ExportSiteMap_PT_Category();
        //Response.Write(Convert.ToString(((int)(10 / 4))));
    }

    private void ExportSiteMap_PhongTro()
    {
        string sitemap = "";
        sitemap = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n";
        sitemap += "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" ";
        sitemap += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
        sitemap += "xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"> ";

        DataTable dtSource = clsPhongTro.PhongTro_FND(1, 1000, "", 0, 0, "", "", "", 2).Tables[0];

        for (int i = 0; i < 1000; i++)
        {
            string strPT_KIEUPHONG = dtSource.Rows[i]["KP_TENKHONGDAU"].ToString().ToLower();
            string strPT_KHUVUC = dtSource.Rows[i]["KV_TENKHONGDAU"].ToString().ToLower();
            string strTIEUDEKHONGDAU = dtSource.Rows[i]["PT_TIEUDEKHONGDAU"].ToString();
            string strPT_ID = dtSource.Rows[i]["PT_ID"].ToString().ToLower();

            string strURL = "http://nato.vn/" + strPT_KIEUPHONG + "/" + strPT_KHUVUC + "/" + strTIEUDEKHONGDAU + "-" + strPT_ID;
            sitemap += "\n<url>";
            sitemap += "\n  <loc>" + strURL + "</loc>";
            sitemap += "\n  <changefreq>Daily</changefreq>";
            sitemap += "\n  <priority>0.8</priority>";
            sitemap += "\n</url> ";
        }

        sitemap += "\n</urlset>";

        System.IO.File.WriteAllText(MapPath("~") + "/Sitemap/sitemap-phongtro.xml", sitemap);
    }
	//Export tin tuc
	private void ExportSiteMap_TinTuc()
    {
        string sitemap = "";
        sitemap = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n";
        sitemap += "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" ";
        sitemap += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
        sitemap += "xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"> ";

        DataTable dtSource = clsTinTuc.TinTuc_FND(1,100,"","","",-1,-1,0).Tables[0];

        for (int i = 0; i < 100; i++)
        {
			string strTI_ID = dtSource.Rows[i]["TI_ID"].ToString().ToLower();
            string strTI_TIEUDEKHONGDAU = dtSource.Rows[i]["ti_tieudekhongdau"].ToString();
			//
            string strURL = "http://nato.vn/tin-tuc/" + strTI_TIEUDEKHONGDAU + "-" + strTI_ID;
            sitemap += "\n<url>";
            sitemap += "\n  <loc>" + strURL + "</loc>";
            sitemap += "\n  <changefreq>Daily</changefreq>";
            sitemap += "\n  <priority>0.8</priority>";
            sitemap += "\n</url> ";
        }

        sitemap += "\n</urlset>";

        System.IO.File.WriteAllText(MapPath("~") + "/Sitemap/sitemap-tintuc.xml", sitemap);
    }
	
	//Export chuyên mục phòng trọ
	private void ExportSiteMap_PT_Category()
    {
        string sitemap = "";
        sitemap = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n";
        sitemap += "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" ";
        sitemap += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
        sitemap += "xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"> ";

		DataTable dtSource = clsKieuPhongTro.fncKieuPhongTro_FND("","");
        for (int i = 0; i < dtSource.Rows.Count; i++)
        {
			string strKP_TENKHONGDAU = dtSource.Rows[i]["kp_tenkhongdau"].ToString().ToLower().Trim();
            string strKP_ID = dtSource.Rows[i]["KP_ID"].ToString().ToLower();

            if (strKP_TENKHONGDAU != "")
            {
                DataTable dtKhuVuc = clsKhuVuc.GetAll();
                for (int j = 0; j < dtKhuVuc.Rows.Count; j++)
                {
                    string strKhVuKD = dtKhuVuc.Rows[j]["kv_tenkhongdau"].ToString().ToLower();
                    string strKV_ID = dtKhuVuc.Rows[j]["KV_ID"].ToString().ToLower();
                    //
                    int iSoBanGhi = clsKieuPhongTro.fnxCountPhongTro(strKP_ID, strKV_ID);
                    int deTongSoTrang = (int)(iSoBanGhi / (int)basConst.PROC_NUMBER);
                    if (deTongSoTrang > 10) deTongSoTrang = 10;
                    if (strKhVuKD != "")
                    {
                        if (deTongSoTrang > 0)
                        {
                            for (int k = 1; k <= deTongSoTrang; k++)
                            {
                                string strURL = "http://nato.vn/" + strKP_TENKHONGDAU + "/" + strKhVuKD + "/0/0/" + k;
                                sitemap += "\n<url>";
                                sitemap += "\n  <loc>" + strURL + "</loc>";
                                sitemap += "\n  <changefreq>Daily</changefreq>";
                                sitemap += "\n  <priority>0.8</priority>";
                                sitemap += "\n</url> ";
                            }
                        }
                    }
                }
            }
        }

        sitemap += "\n</urlset>";

        System.IO.File.WriteAllText(MapPath("~") + "/Sitemap/sitemap-phongtro-category.xml", sitemap);
    }
}
